package com.yc.demo.demo;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 1. 生成验证码（验证码图片，验证码字符串）
 * 2. 图片发送给浏览器， 验证码字符串保存到会话对象中
 * 3. 浏览器显示验证码
 * 4. 用户提交输入的验证码
 * 5. 后台验证
 */
@WebServlet("/vcode.s")
public class VerifyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		// 获取生成的验证码
		String vcode = VerifyCodeUtils.outputImage(response);
		// 从请求对象中获取会话对象， 将验证码保存会话中
		session.setAttribute("vcode", vcode);
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doGet(request, response);
	}

}
